package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.mygdx.game.ui.DragButton;
import com.mygdx.game.ui.Pointer;

public class LuckyRoll extends ApplicationAdapter {
	private SpriteBatch batch;
	private Sprite arrow;
	private Sprite drag;
	private Sprite pannel;
	private Sprite background;
	
	private Texture dragTexture;
	private Texture arrowTexture;
	private Texture panelTexture;
	private Texture backgroundTexture;
	
	
	@Override
	public void create(){
		batch = new SpriteBatch();
		
		dragTexture = new Texture(Gdx.files.internal("drag.png"));
		arrowTexture = new Texture(Gdx.files.internal("arrow.png"));
		panelTexture = new Texture(Gdx.files.internal("pannel.png"));
		backgroundTexture = new Texture(Gdx.files.internal("background.png"));
		
		pannel = new Sprite(panelTexture,0,0,462,462);
		pannel.setPosition(100, 450);
		
		arrow = new Sprite(arrowTexture,0,0,57,225);
		arrow.setPosition(305, 688);
		
		drag = new Sprite(dragTexture,0,0,73,73);
		drag.setPosition(75, 180);
		
		background = new Sprite(backgroundTexture,0,0,600,1200);
		background.setPosition(0, 0);
		
		Gdx.input.setInputProcessor(new InputAdapter () {
		   public boolean touchDown (int x, int y, int pointer, int button) {
			  Gdx.app.log("BasicDemo", "touchDown");
		      return true; // return true to indicate the event was handled
		   }

		   public boolean touchUp (int x, int y, int pointer, int button) {
			   Gdx.app.log("BasicDemo", "touchUp");
			   
			   speed = (x - 100) / 30;
			   
			   drag.setPosition(75, 180);
			   
		      return true; // return true to indicate the event was handled
		   }
		   public boolean touchDragged (int x, int y, int pointer) {
			   Gdx.app.log("BasicDemo", "touchDragged");
			   Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
			   
			   if(x > 450){
				   x = 450;
			   }
			   
			   batch.begin();
			   drag.setPosition(x, 180);
			   drag.draw(batch);
			   arrow.draw(batch);
			   batch.end();
			   
		      return true;
		   }
		});
		
	}
	private float angle = 0f;
	private float speed = 0f;
	private float friction = - 0.05f;
	
	@Override
	public void render(){
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		arrow.setOrigin(28,15);
		angle += speed;
		arrow.setRotation(angle);
		
		batch.begin();
		background.draw(batch);
		pannel.draw(batch);
		arrow.draw(batch);
		drag.draw(batch);
		batch.end();
		if(speed > 0){
			speed += friction;
		}
	}
}
